package cn.jkgly.jsapi.service;

import cn.jkgly.jsapi.entity.Constants;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

/**
 * 微信工具类
 */
public class WechatUtil {

    /**
     * 获得jsapi_ticket
     */

    public static String getJsApiTicket(String token) {
        String url = Constants.JSAPI_TICKET
                + "?access_token=" + token
                + "&type=jsapi";

        String response = HttpClientUtil.doGet(url);

//        WXSessionModel model = JsonUtils.jsonToPojo(response, WXSessionModel.class);

//        String response = OkHttpUtil.doGet(url);
        if (StringUtils.isBlank(response)) {
            return null;
        }
        JSONObject jsonObject = JSONObject.parseObject(response);
        System.out.println(response);
        String ticket = jsonObject.getString("ticket");
        return ticket;
    }

}

